namespace SmartSoft.Controls
{
    using SmartSoft;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Globalization;
    using System.Runtime.CompilerServices;
    using System.Text;
    using System.Windows.Forms;

    [ToolboxBitmap(typeof(TextBox)), DefaultEvent("NumericValueChanged"), DefaultProperty("NumericValue")]
    public class TextNumeric : TextBox
    {
        private Container components;
        private bool ib_AllowNegative = true;
        private bool ib_CheckMovable = true;
        private bool ib_FollowedSystemFont = true;
        private bool ib_NoChangeEvent;
        private bool ib_ZeroIsShown;
        private bool ib_ZeroIsValid = true;
        private Color ic_DisabledBackColor = Color.White;
        private Color ic_DisabledForeColor = Color.Blue;
        private decimal idec_InternalValue;
        private decimal idec_NumericValue;
        private AppInstance.TextNumericFormat ie_TextNumericFormat;
        private int ii_Precision = 10;
        private int ii_ScaleOnFocus = 2;
        private int ii_ScaleOnLostFocus = 2;
        private object oOldValue;

        public event EventHandler NumericValueChanged;

        public TextNumeric()
        {
            this.InitializeComponent();
            base.TextAlign = HorizontalAlignment.Right;
            this.Text = "0";
            base.LostFocus += new EventHandler(this.NumericTextBox_LostFocus);
            base.GotFocus += new EventHandler(this.NumericTextBox_GotFocus);
            base.TextChanged += new EventHandler(this.NumericTextBox_TextChanged);
            base.KeyDown += new KeyEventHandler(this.NumericTextBox_KeyDown);
            base.KeyPress += new KeyPressEventHandler(this.NumericTextBox_KeyPress);
            base.Validating += new CancelEventHandler(this.NumericTextBox_Validating);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        protected string FormatNumber()
        {
            StringBuilder builder = new StringBuilder();
            int num = 1;
            long result = 0L;
            if (!this.Focused)
            {
                while (num <= (this.ii_Precision - this.ii_ScaleOnLostFocus))
                {
                    if (num == 1)
                    {
                        builder.Insert(0, '0');
                    }
                    else
                    {
                        builder.Insert(0, '#');
                    }
                    Math.DivRem((long) num, 3L, out result);
                    if ((result == 0L) && ((num + 1) <= (this.ii_Precision - this.ii_ScaleOnLostFocus)))
                    {
                        builder.Insert(0, ',');
                    }
                    num++;
                }
                num = 1;
                if (this.ii_ScaleOnLostFocus > 0)
                {
                    builder.Append(".");
                    while (num <= this.ii_ScaleOnLostFocus)
                    {
                        builder.Append('0');
                        num++;
                    }
                }
            }
            else
            {
                while (num <= (this.ii_Precision - this.ii_ScaleOnFocus))
                {
                    if (num == 1)
                    {
                        builder.Insert(0, '0');
                    }
                    else
                    {
                        builder.Insert(0, '#');
                    }
                    Math.DivRem((long) num, 3L, out result);
                    if ((result == 0L) && ((num + 1) <= (this.ii_Precision - this.ii_ScaleOnFocus)))
                    {
                        builder.Insert(0, ',');
                    }
                    num++;
                }
                num = 1;
                if (this.ii_ScaleOnFocus > 0)
                {
                    builder.Append(".");
                    while (num <= this.ii_ScaleOnFocus)
                    {
                        builder.Append('0');
                        num++;
                    }
                }
            }
            if (string.IsNullOrEmpty(this.Text))
            {
                this.Text = "0";
            }
            return Convert.ToDecimal(this.Text).ToString(builder.ToString());
        }

        private void InitializeComponent()
        {
            this.components = new Container();
        }

        private void NotShownLostFocus()
        {
            this.ib_NoChangeEvent = true;
            if (this.Text.Equals(string.Empty))
            {
                this.idec_InternalValue = 0M;
            }
            else
            {
                this.idec_InternalValue = Convert.ToDecimal(this.Text);
            }
            if (!this.ZeroIsShown && (this.idec_InternalValue == 0M))
            {
                this.Text = "";
            }
            else
            {
                if (this.ii_ScaleOnLostFocus != 0)
                {
                    this.Text = this.FormatNumber();
                }
                else if (this.Text.IndexOf('-') < 0)
                {
                    this.Text = this.FormatNumber();
                }
                else if (this.Text == "-")
                {
                    this.Text = "";
                }
                else
                {
                    this.Text = this.FormatNumber();
                }
                this.ib_NoChangeEvent = false;
            }
        }

        private void NumericTextBox_GotFocus(object sender, EventArgs e)
        {
            this.ib_NoChangeEvent = true;
            this.OldValue = this.Value;
            this.Text = Convert.ToString(this.idec_InternalValue);
            if (this.ii_ScaleOnFocus != 0)
            {
                this.Text = this.FormatNumber();
            }
            else if (this.Text.IndexOf('-') < 0)
            {
                this.Text = this.FormatNumber();
            }
            else if (this.Text == "-")
            {
                this.Text = "";
            }
            else
            {
                this.Text = this.FormatNumber();
            }
            this.ib_NoChangeEvent = false;
        }

        private void NumericTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            bool flag = false;
            if (this.ii_ScaleOnFocus != 0)
            {
                flag = base.SelectionStart == this.Text.IndexOf(this.DecimalSeperator);
            }
            if (e.KeyCode == Keys.Delete)
            {
                if (flag)
                {
                    base.SelectionStart = this.Text.IndexOf(this.DecimalSeperator) + 1;
                    e.Handled = true;
                }
                else if (this.Text.IndexOf('-') < 0)
                {
                    if (this.SelectionLength == this.Text.Length)
                    {
                        this.Text = "0";
                        base.SelectionStart = 1;
                        e.Handled = true;
                    }
                }
                else if (this.SelectionLength == this.Text.Length)
                {
                    this.Text = "0";
                    base.SelectionStart = 1;
                    e.Handled = true;
                }
                else if (((this.SelectionLength > 0) && (this.SelectedText != "-")) && (Convert.ToDouble(this.SelectedText) == Math.Abs(Convert.ToDouble(this.Text))))
                {
                    this.Text = "0";
                    base.SelectionStart = 1;
                    e.Handled = true;
                }
            }
        }

        private void NumericTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            bool flag = false;
            bool flag2 = false;
            bool flag3 = false;
            int selectionStart = 0;
            flag2 = true;
            if (e.KeyChar.Equals('-') && this.AllowNegative)
            {
                if (this.Text.IndexOf('-') < 0)
                {
                    selectionStart = base.SelectionStart;
                    if (!(Convert.ToDecimal(this.Text) == 0M))
                    {
                        this.Text = "-" + this.Text;
                        base.SelectionStart = selectionStart + 1;
                    }
                    e.Handled = true;
                }
                else
                {
                    if (this.SelectionLength == 0)
                    {
                        selectionStart = base.SelectionStart;
                        this.Text = Convert.ToString((double) (Convert.ToDouble(this.Text) * -1.0));
                        base.SelectionStart = selectionStart - 1;
                        e.Handled = true;
                    }
                    else
                    {
                        if (this.SelectionLength == this.TextLength)
                        {
                            this.Text = "-0";
                        }
                        e.Handled = true;
                    }
                    e.Handled = true;
                }
            }
            else if (e.KeyChar.Equals('+'))
            {
                if (this.Text.IndexOf('-') >= 0)
                {
                    if (this.SelectionLength == 0)
                    {
                        selectionStart = base.SelectionStart;
                        this.Text = Convert.ToString((double) (Convert.ToDouble(this.Text) * -1.0));
                        base.SelectionStart = selectionStart - 1;
                        e.Handled = true;
                    }
                    else if (this.TextLength == this.SelectionLength)
                    {
                        this.Text = "0";
                        e.Handled = true;
                    }
                }
                e.Handled = true;
            }
            else
            {
                if (this.ii_ScaleOnFocus != 0)
                {
                    flag3 = base.SelectionStart == (this.Text.IndexOf(this.DecimalSeperator) + 1);
                }
                if (e.KeyChar == '\b')
                {
                    if (flag3)
                    {
                        base.SelectionStart = this.Text.IndexOf(this.DecimalSeperator);
                        e.Handled = true;
                    }
                    if (this.SelectionLength == this.Text.Length)
                    {
                        this.Text = "0";
                        base.SelectionStart = 1;
                        e.Handled = true;
                    }
                    if (e.KeyChar.Equals(null))
                    {
                        e.Handled = true;
                    }
                }
                else if (("1234567890." + this.DecimalSeperator).IndexOf(e.KeyChar) < 0)
                {
                    e.Handled = true;
                }
                else
                {
                    if (this.ii_ScaleOnFocus != 0)
                    {
                        flag = base.SelectionStart < (this.Text.IndexOf(this.DecimalSeperator) + 1);
                    }
                    if ((e.KeyChar.ToString() == this.DecimalSeperator) || (e.KeyChar.ToString() == "."))
                    {
                        if (flag)
                        {
                            base.SelectionStart = this.Text.IndexOf(this.DecimalSeperator) + 1;
                            this.SelectionLength = 0;
                        }
                        e.Handled = true;
                    }
                    else if ((this.ii_ScaleOnFocus != 0) && (base.SelectionStart == this.Text.Length))
                    {
                        e.Handled = true;
                    }
                    else
                    {
                        if (this.ii_ScaleOnFocus != 0)
                        {
                            if (this.Text.IndexOf('-') < 0)
                            {
                                flag2 = this.Text.Substring(0, this.Text.IndexOf(this.DecimalSeperator)).Length < (this.ii_Precision - this.ii_ScaleOnFocus);
                            }
                            else
                            {
                                flag2 = this.Text.Substring(0, this.Text.IndexOf(this.DecimalSeperator)).Length < ((this.ii_Precision - this.ii_ScaleOnFocus) + 1);
                            }
                        }
                        else if (this.Text.IndexOf('-') < 0)
                        {
                            flag2 = this.Text.Length < this.ii_Precision;
                        }
                        else
                        {
                            flag2 = this.Text.Length < (this.ii_Precision + 1);
                        }
                        if (this.ii_ScaleOnFocus != 0)
                        {
                            if ((this.Text.Substring(0, 1) == "0") && (base.SelectionStart != 0))
                            {
                                flag2 = true;
                            }
                            if (this.SelectionLength > 0)
                            {
                                flag2 = true;
                            }
                        }
                        else
                        {
                            if ((this.Text.Substring(0, 1) == "0") && ((base.SelectionStart == this.Text.Length) || (this.SelectionLength == 1)))
                            {
                                flag2 = true;
                            }
                            if (this.SelectionLength > 0)
                            {
                                flag2 = true;
                            }
                        }
                        if (this.ii_ScaleOnFocus != 0)
                        {
                            if (flag && !flag2)
                            {
                                e.Handled = true;
                            }
                        }
                        else if (!flag2)
                        {
                            e.Handled = true;
                        }
                    }
                }
            }
        }

        private void NumericTextBox_LostFocus(object sender, EventArgs e)
        {
            this.NotShownLostFocus();
        }

        private void NumericTextBox_TextChanged(object sender, EventArgs e)
        {
            int selectionStart = 0;
            bool flag = false;
            if (!this.ib_NoChangeEvent && (base.SelectionStart != -1))
            {
                this.ib_NoChangeEvent = true;
                if (string.Empty.Equals(this.Text.Trim()))
                {
                    this.Text = "0";
                    base.SelectionStart = this.Text.Length;
                }
                if (this.Text.Substring(0, 1) == this.GroupSeperator)
                {
                    this.Text = this.Text.Substring(1);
                }
                if (this.ii_ScaleOnFocus != 0)
                {
                    if (base.SelectionStart == this.Text.IndexOf(this.DecimalSeperator))
                    {
                        flag = true;
                    }
                    else
                    {
                        selectionStart = base.SelectionStart;
                    }
                }
                else if (this.Text.Length < base.SelectionStart)
                {
                    selectionStart = base.SelectionStart;
                }
                else
                {
                    selectionStart = this.Text.Length - base.SelectionStart;
                }
                try
                {
                    this.idec_InternalValue = Convert.ToDecimal(this.Text);
                    this.Value = Convert.ToDecimal(this.Text);
                }
                catch
                {
                    this.Text = "0";
                    this.idec_InternalValue = Convert.ToDecimal(this.Text);
                    this.Value = Convert.ToDecimal(this.Text);
                }
                if (this.Focused)
                {
                    if (this.ii_ScaleOnFocus != 0)
                    {
                        this.Text = this.FormatNumber();
                    }
                    else if (this.Text.IndexOf('-') < 0)
                    {
                        this.Text = this.FormatNumber();
                    }
                    else if (this.Text.Equals('-'))
                    {
                        this.Text = "";
                    }
                    else
                    {
                        this.Text = this.FormatNumber();
                    }
                }
                else if (this.ii_ScaleOnLostFocus != 0)
                {
                    this.Text = this.FormatNumber();
                }
                else if (this.Text.IndexOf('-') < 0)
                {
                    this.Text = this.FormatNumber();
                }
                else if (this.Text.Equals('-'))
                {
                    this.Text = "";
                }
                else
                {
                    this.Text = this.FormatNumber();
                }
                if (this.ii_ScaleOnFocus != 0)
                {
                    if (flag)
                    {
                        base.SelectionStart = this.Text.IndexOf(this.DecimalSeperator);
                    }
                    else
                    {
                        base.SelectionStart = selectionStart;
                    }
                }
                else if (this.Text.Length <= selectionStart)
                {
                    base.SelectionStart = selectionStart;
                }
                else
                {
                    base.SelectionStart = this.Text.Length - selectionStart;
                }
                this.ib_NoChangeEvent = false;
            }
        }

        private void NumericTextBox_Validating(object sender, CancelEventArgs e)
        {
            if ((((this.Text.Equals(string.Empty) || this.Value.Equals(DBNull.Value) || this.Value.Equals(SDBNull.Value)) || Convert.ToDecimal(this.Value).Equals(Convert.ToDecimal(0))) && !this.ZeroIsValid) || !this.CheckMovable)
            {
                e.Cancel = true;
            }
        }

        protected override void OnBackColorChanged(EventArgs e)
        {
            base.OnBackColorChanged(e);
            base.Invalidate();
        }

        protected override void OnCreateControl()
        {
            if (this.FollowedSystemFont)
            {
                this.Font = AppInstance.SystemFont;
            }
            this.NotShownLostFocus();
            base.OnCreateControl();
        }

        protected override void OnForeColorChanged(EventArgs e)
        {
            base.OnForeColorChanged(e);
            base.Invalidate();
        }

        protected void OnNumericValueChanged(EventArgs e)
        {
            if (this.NumericValueChanged != null)
            {
                this.NumericValueChanged(this, e);
            }
        }

        private void SetNumericFormat()
        {
            if (AppInstance.NumberDigits != 0)
            {
                switch (this.UserTextNumericFormat)
                {
                    case AppInstance.TextNumericFormat.None:
                        return;

                    case AppInstance.TextNumericFormat.Quantity:
                        this.NumericPrecision = AppInstance.NumberDigits + AppInstance.QuantityDecimals;
                        this.NumericScaleOnFocus = AppInstance.QuantityDecimals;
                        this.NumericScaleOnLostFocus = AppInstance.QuantityDecimals;
                        return;

                    case AppInstance.TextNumericFormat.NormQuantity:
                        this.NumericPrecision = AppInstance.NumberDigits + AppInstance.NormQuantity;
                        this.NumericScaleOnFocus = AppInstance.NormQuantity;
                        this.NumericScaleOnLostFocus = AppInstance.NormQuantity;
                        return;

                    case AppInstance.TextNumericFormat.RatioQuantity:
                        this.NumericPrecision = AppInstance.NumberDigits + AppInstance.RatioFormat;
                        this.NumericScaleOnFocus = AppInstance.RatioFormat;
                        this.NumericScaleOnLostFocus = AppInstance.RatioFormat;
                        return;

                    case AppInstance.TextNumericFormat.LocalPrice:
                        this.NumericPrecision = AppInstance.NumberDigits + AppInstance.LCPriceDecimals;
                        this.NumericScaleOnFocus = AppInstance.LCPriceDecimals;
                        this.NumericScaleOnLostFocus = AppInstance.LCPriceDecimals;
                        return;

                    case AppInstance.TextNumericFormat.ForeignPrice:
                        this.NumericPrecision = AppInstance.NumberDigits + AppInstance.FCPriceDecimals;
                        this.NumericScaleOnFocus = AppInstance.FCPriceDecimals;
                        this.NumericScaleOnLostFocus = AppInstance.FCPriceDecimals;
                        return;

                    case AppInstance.TextNumericFormat.LocalAmount:
                        this.NumericPrecision = AppInstance.NumberDigits + AppInstance.LCAmountDecimals;
                        this.NumericScaleOnFocus = AppInstance.LCAmountDecimals;
                        this.NumericScaleOnLostFocus = AppInstance.LCAmountDecimals;
                        return;

                    case AppInstance.TextNumericFormat.ForeignAmount:
                        this.NumericPrecision = AppInstance.NumberDigits + AppInstance.FCAmountDecimals;
                        this.NumericScaleOnFocus = AppInstance.FCAmountDecimals;
                        this.NumericScaleOnLostFocus = AppInstance.FCAmountDecimals;
                        return;

                    case AppInstance.TextNumericFormat.Percent:
                        this.NumericPrecision = AppInstance.NumberDigits + AppInstance.PercentDecimals;
                        this.NumericScaleOnFocus = AppInstance.PercentDecimals;
                        this.NumericScaleOnLostFocus = AppInstance.PercentDecimals;
                        return;

                    case AppInstance.TextNumericFormat.ExchangeRate:
                        this.NumericPrecision = AppInstance.NumberDigits + AppInstance.ExchangeFormat;
                        this.NumericScaleOnFocus = AppInstance.ExchangeFormat;
                        this.NumericScaleOnLostFocus = AppInstance.ExchangeFormat;
                        return;

                    case AppInstance.TextNumericFormat.IntNumber:
                        this.NumericPrecision = AppInstance.NumberDigits;
                        this.NumericScaleOnFocus = 0;
                        this.NumericScaleOnLostFocus = 0;
                        return;
                }
            }
        }

        [Category("Numeric settings"), DefaultValue(true)]
        public bool AllowNegative
        {
            get
            {
                return this.ib_AllowNegative;
            }
            set
            {
                this.ib_AllowNegative = value;
            }
        }

        [Description("Indicates if it is movable cell."), RefreshProperties(RefreshProperties.All), DefaultValue(true), Category("Numeric settings")]
        public bool CheckMovable
        {
            get
            {
                return this.ib_CheckMovable;
            }
            set
            {
                this.ib_CheckMovable = value;
            }
        }

        private string DecimalSeperator
        {
            get
            {
                return NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
            }
        }

        [RefreshProperties(RefreshProperties.All), DefaultValue(typeof(Color), "White"), Category("Numeric settings"), Description("To get or set disabled color.")]
        public Color DisabledBackColor
        {
            get
            {
                return this.ic_DisabledBackColor;
            }
            set
            {
                if (this.ic_DisabledBackColor != value)
                {
                    this.ic_DisabledBackColor = value;
                    this.OnBackColorChanged(EventArgs.Empty);
                }
            }
        }

        [DefaultValue(typeof(Color), "Blue"), RefreshProperties(RefreshProperties.All), Category("Numeric settings"), Description("To get or set disabled color.")]
        public Color DisabledForeColor
        {
            get
            {
                return this.ic_DisabledForeColor;
            }
            set
            {
                if (this.ic_DisabledForeColor != value)
                {
                    this.ic_DisabledForeColor = value;
                    this.OnForeColorChanged(EventArgs.Empty);
                }
            }
        }

        public bool Enabled
        {
            get
            {
                return base.Enabled;
            }
            set
            {
                if (base.Enabled != value)
                {
                    base.Enabled = value;
                    this.OnForeColorChanged(EventArgs.Empty);
                    this.OnBackColorChanged(EventArgs.Empty);
                }
            }
        }

        [DefaultValue(true)]
        public bool FollowedSystemFont
        {
            get
            {
                return this.ib_FollowedSystemFont;
            }
            set
            {
                this.ib_FollowedSystemFont = value;
            }
        }

        private string GroupSeperator
        {
            get
            {
                return NumberFormatInfo.CurrentInfo.NumberGroupSeparator;
            }
        }

        [Category("Numeric settings"), DefaultValue(10)]
        public int NumericPrecision
        {
            get
            {
                return this.ii_Precision;
            }
            set
            {
                if (value < 0)
                {
                    MessageBox.Show("Precision cannot be negative!", "Numeric TextBox", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    if (value < this.NumericScaleOnFocus)
                    {
                        this.NumericScaleOnFocus = value;
                    }
                    this.ii_Precision = value;
                }
            }
        }

        [RefreshProperties(RefreshProperties.All), Category("Numeric settings"), DefaultValue(2)]
        public int NumericScaleOnFocus
        {
            get
            {
                return this.ii_ScaleOnFocus;
            }
            set
            {
                if (value < 0)
                {
                    MessageBox.Show("Scale cannot be negative!", "Numeric TextBox", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (value >= this.NumericPrecision)
                {
                    MessageBox.Show("Scale cannot be larger than precission!", "Numeric TextBox", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    this.ii_ScaleOnFocus = value;
                    if (this.ii_ScaleOnFocus > 0)
                    {
                        this.Text = "0" + this.DecimalSeperator + new string(Convert.ToChar("0"), this.ii_ScaleOnFocus);
                    }
                    else
                    {
                        this.Text = "0";
                    }
                }
            }
        }

        [DefaultValue(2), RefreshProperties(RefreshProperties.All), Category("Numeric settings")]
        public int NumericScaleOnLostFocus
        {
            get
            {
                return this.ii_ScaleOnLostFocus;
            }
            set
            {
                if (value < 0)
                {
                    MessageBox.Show("Scale cannot be negative!", "Numeric TextBox", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (value >= this.NumericPrecision)
                {
                    MessageBox.Show("Scale cannot be larger than precesion!", "Numeric TextBox", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    this.ii_ScaleOnLostFocus = value;
                }
            }
        }

        [Category("Numeric settings"), Bindable(true)]
        public decimal NumericValue
        {
            get
            {
                return this.idec_NumericValue;
            }
            set
            {
                if (value.Equals((decimal) 0M))
                {
                    if (this.ZeroIsShown)
                    {
                        this.Text = Convert.ToString(0);
                    }
                    else
                    {
                        this.ib_NoChangeEvent = true;
                        this.Text = "";
                    }
                    this.idec_NumericValue = Convert.ToDecimal(0);
                    this.OnNumericValueChanged(new EventArgs());
                }
                else if (!value.Equals(this.idec_NumericValue))
                {
                    this.ib_NoChangeEvent = false;
                    this.Text = Convert.ToString(value);
                    this.idec_NumericValue = Convert.ToDecimal(value);
                    this.OnNumericValueChanged(new EventArgs());
                }
            }
        }

        public object OldValue
        {
            get
            {
                return this.oOldValue;
            }
            set
            {
                if (this.oOldValue != value)
                {
                    this.oOldValue = value;
                }
            }
        }

        [Description("Get or set numeric format."), DefaultValue(0), RefreshProperties(RefreshProperties.All), Category("Numeric settings")]
        public AppInstance.TextNumericFormat UserTextNumericFormat
        {
            get
            {
                return this.ie_TextNumericFormat;
            }
            set
            {
                if (this.ie_TextNumericFormat != value)
                {
                    this.ie_TextNumericFormat = value;
                    this.SetNumericFormat();
                }
            }
        }

        [Bindable(true), Category("Numeric settings")]
        public object Value
        {
            get
            {
                if (this.idec_InternalValue.Equals((decimal) 0M))
                {
                    return DBNull.Value;
                }
                return this.idec_NumericValue;
            }
            set
            {
                if ((value.Equals(DBNull.Value) || value.Equals(SDBNull.Value) || value.Equals(0)) || (value.Equals(null) || value.Equals(string.Empty)))
                {
                    if (this.ZeroIsShown)
                    {
                        this.Text = Convert.ToString(0);
                    }
                    else
                    {
                        this.ib_NoChangeEvent = true;
                        this.Text = "";
                    }
                    this.idec_NumericValue = Convert.ToDecimal(0);
                    this.OnNumericValueChanged(new EventArgs());
                }
                else if (!value.Equals(this.idec_NumericValue))
                {
                    this.ib_NoChangeEvent = false;
                    this.Text = Convert.ToString(value);
                    this.idec_NumericValue = Convert.ToDecimal(value);
                    this.OnNumericValueChanged(new EventArgs());
                }
            }
        }

        [Browsable(false), RefreshProperties(RefreshProperties.All), Category("Numeric settings"), Description("Indicating value has been changed.")]
        public bool ValueChanged
        {
            get
            {
                return !this.OldValue.Equals(this.Value);
            }
        }

        [Category("Numeric settings"), DefaultValue(false)]
        public bool ZeroIsShown
        {
            get
            {
                return this.ib_ZeroIsShown;
            }
            set
            {
                this.ib_ZeroIsShown = value;
            }
        }

        [DefaultValue(true), Category("Numeric settings")]
        public bool ZeroIsValid
        {
            get
            {
                return this.ib_ZeroIsValid;
            }
            set
            {
                this.ib_ZeroIsValid = value;
            }
        }
    }
}

